package com.semidata.trp.decision.business;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.semidata.rtd.core.log.Logger;
import com.semidata.trp.decision.report.Click;
import com.semidata.trp.decision.report.Cost;
import com.semidata.trp.decision.report.Impression;
import com.semidata.trp.decision.report.ResourceReport;
import com.semidata.trp.decision.report.StrategyImpr;
import com.semidata.trp.decision.report.StrategyReport;
import com.semidata.trp.message.business.SyncReport;

public class ReportData {
	Map<Integer, StrategyReport> strategyReport = new HashMap<>();
	Map<Integer, ResourceReport> resourceReport = new HashMap<>();
	Map<Integer, Cost> orgReport = new HashMap<>();

	public ReportData() {

	}

	public ReportData(SyncReport.SyncReportData data) {
		//add org cost
		List<SyncReport.Cost> orgDatas = data.getOrgCostListList();
		for (SyncReport.Cost cost : orgDatas) {
			Cost orgCost = new Cost(cost.getId(), cost.getTodayIn(),
					cost.getTotalIn(), cost.getTodayOut(), cost.getTotalOut(),
					cost.getTodayAlly(), cost.getTotalAlly());
			Logger.log("DEBUG", "get org report : " + orgCost.toString() );
			orgReport.put(cost.getId(), orgCost);
		}
		//add strategy cost
		List<SyncReport.Cost> strategyCosts = data.getStrategyCostListList();
		for (SyncReport.Cost cost : strategyCosts) {
			Cost strategyCost = new Cost(cost.getId(), cost.getTodayIn(),
					cost.getTotalIn(), cost.getTodayOut(), cost.getTotalOut(),
					cost.getTodayAlly(), cost.getTotalAlly());
			
			if (!this.strategyReport.containsKey(cost.getId())
					|| this.strategyReport.get(cost.getId()) == null)
				this.strategyReport.put(cost.getId(), new StrategyReport());
			StrategyReport strategyReport = this.strategyReport.get(cost
					.getId());
			Logger.log("DEBUG", "get strategy cost : " + strategyCost.toString());
			strategyReport.setCost(strategyCost);
		}
		//add resource click
		List<SyncReport.Click> resourceClicks = data.getResourceClickListList();
		for (SyncReport.Click click : resourceClicks) {
			Click resourceClick = new Click(click.getId(), click.getToday(),
					click.getTotal());
			if (!this.resourceReport.containsKey(click.getId())
					|| this.resourceReport.get(click.getId()) == null)
				this.resourceReport.put(click.getId(), new ResourceReport());
			ResourceReport resourceReport = this.resourceReport.get(click
					.getId());
			Logger.log("DEBUG", "get resource click : " + resourceClick.toString());
			resourceReport.setClick(resourceClick);
		}
		//add strategy click
		List<SyncReport.Click> strategyClicks = data.getStrategyClickListList();
		for (SyncReport.Click click : strategyClicks) {
			Click strategyClick = new Click(click.getId(), click.getToday(),
					click.getTotal());
			if (!this.strategyReport.containsKey(click.getId())
					&& this.strategyReport.get(click.getId()) == null)
				this.strategyReport.put(click.getId(), new StrategyReport());
			StrategyReport strategyReport = this.strategyReport.get(click
					.getId());
			Logger.log("DEBUG", "get strategy click : " + strategyClick.toString());
			strategyReport.setClick(strategyClick);
		}
		//add resource impression
		List<SyncReport.Impression> resourceImprs = data
				.getResourceImprListList();
		for (SyncReport.Impression impression : resourceImprs) {
			Impression resourceImpr = new Impression(impression.getId(),
					impression.getToday(), impression.getTotal());
			if (!this.resourceReport.containsKey(impression.getId())
					|| this.resourceReport.get(impression.getId()) == null)
				this.resourceReport.put(impression.getId(),
						new ResourceReport());
			ResourceReport resourceReport = this.resourceReport.get(impression
					.getId());
			Logger.log("DEBUG", "get resource impression : " + resourceImpr);
			resourceReport.setImpr(resourceImpr);
		}
		//add strategy impression
		List<SyncReport.StrategyImpr> strategyImprs = data
				.getStrategyImprListList();
		for (SyncReport.StrategyImpr impression : strategyImprs) {
			StrategyImpr strategyImpr = new StrategyImpr(impression.getId(),
					impression.getTodayIn(), impression.getTotalIn(),
					impression.getTodayOut(), impression.getTotalOut(),
					impression.getTodayAlly(), impression.getTotalAlly());
			if (!this.strategyReport.containsKey(impression.getId()) || this.strategyReport.get(impression.getId()) == null)
				this.strategyReport.put(impression.getId(), new StrategyReport());
			StrategyReport strategyReport = this.strategyReport.get(impression.getId());
			Logger.log("DEBUG", "get strategy impression : " + strategyImpr);
			strategyReport.setImpr(strategyImpr);
		}

	}

	public Map<Integer, StrategyReport> getStrategyReport() {
		return strategyReport;
	}

	public Map<Integer, ResourceReport> getResourceReport() {
		return resourceReport;
	}

	public Map<Integer, Cost> getOrgReport() {
		return orgReport;
	}
	
	

}
